package cn.com.thinvent.dispatch.web.controller;

import cn.com.thinvent.dispatch.entity.Indicator;
import cn.com.thinvent.dispatch.entity.ModelTarget;
import cn.com.thinvent.dispatch.entity.response.PagedGridResult;
import cn.com.thinvent.dispatch.entity.response.ReturnModel;
import cn.com.thinvent.dispatch.service.biz.IndicatorService;
import cn.com.thinvent.dispatch.service.biz.ModelTargetService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 指标controller
 */
@Api(description = "Indicator模块")
@Controller
@RequestMapping("/indicator")
@CrossOrigin(origins = "*")
@ResponseBody
public class IndicatorController {
    @Autowired
    private IndicatorService indicatorService;

    /**
     * 指标列表
     * @param name
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    @ResponseBody
    public ReturnModel list(@RequestParam("name") String name,
                            @RequestParam("pageNum") Integer pageNum,
                            @RequestParam("pageSize") Integer pageSize) {
        PagedGridResult<Indicator> list = indicatorService.list(name, pageNum, pageSize);
        return new ReturnModel(200, list, "");
    }
    /**
     * 新增指标
     * @param indicator
     * @return
     */
    @PostMapping("/saveOrUpdate")
    @ResponseBody
    public ReturnModel saveOrUpdate(@RequestBody Indicator indicator) {
        Indicator target = indicatorService.saveOrUpdate(indicator);
        return new ReturnModel(200, target, "");
    }

    /**
     * 删除指标
     * @param indicator
     * @return
     */
    @PostMapping("/delete")
    @ResponseBody
    public ReturnModel delete(@RequestBody Indicator indicator) {
        Integer delete = indicatorService.delete(indicator.getId());
        return new ReturnModel(200, delete, "");
    }

}
